<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1>AJAX请求失败处理</h1>
    <input type="button" value="获取响应数据" onclick="get_data()">
    <script>
        function get_data(){
            let xhr = new XMLHttpRequest()

            xhr.open('get','http://httpbin.org/get')

            xhr.send()

            xhr.onreadystatechange = ()=>{
                if(xhr.readyState == 4){
                    console.log(xhr.status)
                }
            }
            //请求失败
            xhr.onerror = () =>{
                console.log('网络中断')
            }
        }

    </script>
</body>
</html>